package aooO.crm.common.Interceptor;

import aooO.crm.pojo.User;
import aooO.crm.pojo.stateCode;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class loginInterceptor implements HandlerInterceptor {
    //springMVC带的拦截器

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //在请求之前进行登录验证
        //取出会话域的user对象  如果存在 则允许访问
        User user = (User) request.getSession().getAttribute(stateCode.SESSION_USER);
        if (user==null){
            //还未登录 重定向到登录界面
            response.sendRedirect("/");
            return false;
        }
        return true;
    }
}
